using System;
using System.Collections.Generic;
using System.Text;
using EntidadesTO;
using System.Data;
using System.Data.SqlClient;

namespace AccesoDatos
{
    public class RegimenDeclaradoDA
    {
        public List<RegimenDeclaradoTO> ListarRegimenDeclarado()
        {
            List<RegimenDeclaradoTO> listaRegimenDeclarado = new List<RegimenDeclaradoTO>();
            SqlDataReader reader = null;
            SqlCommand comando;
            ConexionBD instanciaConexion = ConexionBD.ObtenerInstancia();

            try
            {

                instanciaConexion.AbrirConexion();
                comando = new SqlCommand("sp_get_SEC_RegimenDeclarado_all", instanciaConexion.ObtenerConexion());
                comando.CommandType = CommandType.StoredProcedure;

                reader = comando.ExecuteReader();

                RegimenDeclaradoTO regimenDeclaradoTO = new RegimenDeclaradoTO();
                regimenDeclaradoTO.CodRegimenDeclarado = -1;
                regimenDeclaradoTO.DesRegimenDeclarado = "--Seleccione un elemento--";

                listaRegimenDeclarado.Add(regimenDeclaradoTO);

                while (reader.Read())
                {
                    regimenDeclaradoTO = new RegimenDeclaradoTO();
                    regimenDeclaradoTO.CodRegimenDeclarado = reader.GetInt32(reader.GetOrdinal("codRegimenDeclarado"));
                    regimenDeclaradoTO.DesRegimenDeclarado = reader.GetString(reader.GetOrdinal("desRegimenDeclarado"));

                    listaRegimenDeclarado.Add(regimenDeclaradoTO);
                }

                reader.Close();
                instanciaConexion.CerrarConexion();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                listaRegimenDeclarado = null;

            }
            finally
            {
                if (reader != null)
                {
                    if (reader.IsClosed == false)
                        reader.Close();
                }
                if (instanciaConexion.ObtenerConexion().State != ConnectionState.Closed)
                {
                    instanciaConexion.CerrarConexion();
                }
            }

            return listaRegimenDeclarado;

        }
    }
}
